/* 
接口请求函数模块
*/
import request from './request'

// 登陆
export const reqLogin = (username, pwd) => request({
  url: '/admin/login',
  method: 'post',
  data: {username, pwd}
})

// 获取用户信息
export const reqInfo = () => request('/admin/info')

// 退出登陆
export const reqLogout = () => request('/admin/logout')

// 添加用户
export const reqAddUser = (user) => request({
  url: '/admin/user',
  method: 'post',
  data: user
})

// 获取用户列表
export const reqGetUsers = (page, limit) => request({
  url: `/admin/user/${page}/${limit}`,
  method: 'GET',
})

// 获取用户
export const reqGetUser = (id) => request({
  url: `/admin/user`,
  method: 'GET',
  params: {id}
})

// 更新用户
export const reqUpdateUser = (formData) => request({
  url: '/admin/user',
  method: 'PUT',
  data: formData  // 后台formidable来解析这个数据
})

// const formData = new FormData()
// formData.set('_id', 'abc')
// formData.set('username', 'atguigu')
// formData.set('profileFile', 文件对象)

// 删除用户
export const reqDeleteUser = (id) => request({
  url: `/admin/user/${id}`,
  method: 'delete'
})